package entity;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;

/**
 *
 * @author Chenhui
 */
@Entity
public class PortfolioEntryEntity implements Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String timeCreated;
    private String latestValuation;
    private float risk;
    
    @OneToMany(cascade={CascadeType.PERSIST}, mappedBy="portfolioEntry")
    private Collection<EntryHistoryEntity> entryHistory=new ArrayList<EntryHistoryEntity>();
    
    @OneToOne(cascade={CascadeType.PERSIST})
    private FinancialInstrumentEntity financialInstrument;
    
    public PortfolioEntryEntity(){}
    
    public void create(){
    setTimeCreated();
    }
    
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

   public String getTimeCreated() {
        return timeCreated;
    }

    public void setTimeCreated() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.timeCreated = dateFormat.format(new Date());
    }

    public String getLatestValuation() {
        return latestValuation;
    }

    public void setLatestValuation(String latestValuation) {
        this.latestValuation = latestValuation;
    }

    public float getRisk() {
        return risk;
    }

    public void setRisk(float risk) {
        this.risk = risk;
    }

    public Collection<EntryHistoryEntity> getEntryHistory() {
        return entryHistory;
    }

    public void setEntryHistory(Collection<EntryHistoryEntity> entryHistory) {
        this.entryHistory = entryHistory;
    }

    public FinancialInstrumentEntity getFinancialInstrument() {
        return financialInstrument;
    }

    public void setFinancialInstrument(FinancialInstrumentEntity financialInstrument) {
        this.financialInstrument = financialInstrument;
    }
    
    
}
